package com.tsing.cloud.controller;

import com.tsing.cloud.bean.Payment;
import com.tsing.cloud.mapper.PaymentMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author TheTsing
 * @version 1.0
 * @date 2021/11/8 11:13
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String port;

    @Resource
    private PaymentMapper paymentMapper;

    @GetMapping("/getAll/{id}")
    public List<Payment> getAll(@PathVariable("id") String id) {
        System.out.println("**********" + port);
        List<Payment> payments = paymentMapper.selectList(null);
        payments.add(new Payment().setName("cloud-provider-payment8001").setId(id));
        return payments;
    }

    @GetMapping("/timeout")
    public String timeout() {
        System.out.println("**********" + port);
        try {
            TimeUnit.MILLISECONDS.sleep(3000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "timeout" + port;
    }

}
